<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
</style>

<body>
    <p class="test" id="test">
        这个是用来测试
    </p>
</body>
<script>
    window.onload = function () {
        // 全局变量不能通过delete删除 而window对象上定义的变量能通过delete删除
        var age = 29;
        window.color = 'red';
        delete age;
        delete window.color;
        console.log(age); //29
        console.log(window.color); //undefined

        var leftPos = (typeof window.screenLeft === 'number') ? window.screenLeft : window.screenX;
        var topPos = (typeof window.screenTop === 'number') ? window.screenTop : window.screenY;

        console.log("leftPos:" + leftPos + ',' + "topPos:" + topPos);

        console.log("window.innerHeight:" + window.innerHeight);
        console.log("window.innerWidth:" + window.innerWidth);

        // 获取页面视口大小 （除去边栏边框）

        (function () {
            var viewportWidth = window.innerWidth;
            var viewportHeight = window.innerHeight;

            if (typeof viewportWidth !== "number") {
                //判断浏览器是否处于标准模式 
                if (document.compatMode === 'CSS1Compat') {
                    viewportHeight = document.documentElement.clientHeight;
                    viewportWidth = document.documentElement.clientWidth;
                } else {
                    viewportHeight = document.body.clientHeight;
                    viewportWidth = document.body.clientWidth;
                }
            }

            console.log("viewportWidth:" + viewportWidth);
            console.log("viewportHeight:" + viewportHeight);
        })();

        //使用间歇调用  需要使用 window.clearInterval
        (function () {
            var num = 0;
            var max = 3;

            function increNum() {
                num++;
                if (num <= max) {
                    console.log('间歇调用:' + num);
                } else {
                    console.log("手动使用清除间歇调用");
                    window.clearInterval(intervarId);
                }
            }
            var intervarId = setInterval(increNum, 1000);
        })();

        // 使用超时调用模拟间歇调用 不需要使用清除超时操作 而且不用担心后一个间歇调 用可能会在前一个间歇调用结束之前启动
        // 最好不要使用间歇调用
        (function () {
            var num = 0;
            var max = 3;

            function increNum() {
                 num++;
                if (num <= max) {
                    console.log('超时调用:' + num);
                    setTimeout(increNum, 1000);
                } else {
                    console.log("自动停止超时调用");
                }
            }
            setTimeout(increNum, 1000);
        })();
    }
</script>



</html>